<?php

namespace app\admin\command;

use think\Config;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Exception;
use think\Db;
use AlibabaCloud\SDK\Imageseg\V20191230\Imageseg;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config as aliconfig;
use AlibabaCloud\SDK\Imageseg\V20191230\Models\SegmentHeadAdvanceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use GuzzleHttp\Psr7\Stream;
class Broadcast extends Command
{
    protected function configure()
    {
        $this
            ->setName('broadcast')
            ->setDescription('broadcast');
    }

    protected function execute(Input $input, Output $output)
    {

        //$broadcast_images = Db::name('broadcastImage')->whereTime('updatetime','-3 days')->field('id,broadcast_id,images')->select();
        $broadcast_images =[];
        $imagephoto=[];
        foreach ($broadcast_images as $key => $value) {
                if(!empty($value['images'])){
                    $photos =  explode(',',$value['images']);
                    foreach ($photos as $k => $v) {
                    $res = Db::name('broadcastImagePhoto')->where('image',$v)->find();
                    if(empty($res)){
                        $imagephoto[] = [
                            'broadcast_id'=>$value['broadcast_id'],
                            'broadcast_image_id'=>$value['id'],
                            'image'=>$v,
                            'createtime'=>time(),
                            'updatetime'=>time(),
                            'status'=>1
                        ];
                    }
                    }
                }
        }
        if(!empty($imagephoto)){
            Db::name('broadcast_image_photo')->insertAll($imagephoto);
        }
        
    }

    
}
